﻿using System.Net;
using System.Net.Sockets;
using System.Text;

namespace Client
{
    internal class ClientStart
    {
        static void Main(string[] args)
        {
            CreateBasicClient();
        }

        static void CreateBasicClient()
        {
            //1 创建Socket
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPAddress iPAddress = new IPAddress(new byte[] { 127, 0, 0, 1 });
            EndPoint pt = new IPEndPoint(iPAddress, 17666);

            //2 连接服务器
            socket.Connect(pt);
            Console.WriteLine("Client Start...");

            //3 接受数据
            byte[] dataRcv = new byte[1024];
            int len=socket.Receive(dataRcv);
            string msgRcv = Encoding.UTF8.GetString(dataRcv, 0, len);
            Console.WriteLine("Rcv Client Data:" + msgRcv);

            //4 发送数据
            string msgSend=Console.ReadLine();
            socket.Send(Encoding.UTF8.GetBytes(msgSend));

            Console.ReadKey();

        }

     
    }
}